#ifndef HDVIEWPORT_H
#define HDVIEWPORT_H

#include <GL\GLee.h>
#include <QGLWidget>
#include "camera.h"
#include "mesh.h"
#include "hdcontroller.h"

#define ENUM_NAME(o,e,v) (o::staticMetaObject.enumerator(o::staticMetaObject.indexOfEnumerator(#e)).valueToKey((v)))

class HDViewport : public QGLWidget
{
    Q_OBJECT

public:
    HDViewport(QWidget* parent = 0);

    enum CameraType
    {
        Left,
        Top,
        Right,
        Bottom,
        Front,
        Back,
        Perspective,
        Custom
    };
    Q_ENUMS(CameraType);

//////////////////////////////////////////////////////////////////////////
// Getters and Setters
//////////////////////////////////////////////////////////////////////////
	/*
    QImage Image();
    void SetImage(QImage img);

	void initializeGL();
	void paintEvent(QPaintEvent *event);


	void focusInEvent(QFocusEvent * event);
	void focusOutEvent(QFocusEvent *event);

	void CreateGradient();
	void LoadGLTextures();
	void DrawBackground();

	void DrawGLScene(bool SelectMode = false);
	void DrawGrid();
	void DrawForeground();
	int SelectObjectAt(const QPoint &pos);
	*/

	void SaveGLState();
	void RestoreGLState();

    CameraType CameraView();
    void SetCameraView(CameraType view);
protected:
    void resizeGL(int width, int height);    
	void paintGL();

    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);
    void keyPressEvent(QKeyEvent *event);
private:
//////////////////////////////////////////////////////////////////////////
// Member Variables
//////////////////////////////////////////////////////////////////////////
public:
	GLfloat Minv[16];
    QPointF pntOffset;
    GLfloat rotationX;
    GLfloat rotationY;
	GLfloat zoom;
	CameraType view;
private:
	QPoint pntMouseDown;
    QRadialGradient gradient;
    bool wireframe;
    bool solid;

	QPoint pntA, pntB;
	bool isMouseDown;

	MovingPlane selectedPlane;

//////////////////////////////////////////////////////////////////////////
// Private Functions
//////////////////////////////////////////////////////////////////////////	
	void InitGL();
	void SetupMatrices();
	void UpdateSelectedVertex(QPoint position);

public:
	Mesh *_mainMesh;
	QList<gfxTool*> Tools;
	Vertex3f *first, *second, *target, *tmpVertex;
};

#endif // HDVIEWPORT_H
